package LogServer.utils

import java.io.{File, FileInputStream}
import java.util.Properties

/**
  * Created by root on 17-2-14.
  */

class PropertiesUtil{
  /**
    * 将perperties文件转化成Properties Object
    * @param path 文件路径
    * @return Properties Object
    */
  def loadProperties(path: String): Properties = {
    val file = new File(path)
    val fileInputStream = new FileInputStream(file)
    val properties = new Properties()
    properties.load(fileInputStream)
    properties
  }

  /**
    * 调用getResourceAsStream()获得Properties Object
    * @param fileName
    * @return Properties Object
    */
  def loadResources(fileName: String): Properties = {
    //  path 不以’/'开头时默认是从此类所在的包下取资源，以’/'开头则是从根目录
    val in = this.getClass().getResourceAsStream("/"+fileName)
    val properties = new Properties()
    properties.load(in)
    properties
  }

  /**
    *
    * @param propertyName 属性名称
    * @param properties Properties文件
    * @return 指定属性的值
    */
  def getString(propertyName: String, properties: Properties): String = {
    properties.getProperty(propertyName)
  }

}
